package com.situ.orderingsystem.service.impl;

import com.situ.orderingsystem.dao.LoginDAo;
import com.situ.orderingsystem.dao.impl.LoginDaoImpl;
import com.situ.orderingsystem.model.User;
import com.situ.orderingsystem.service.LoginService;
import com.situ.orderingsystem.utils.BeanFactory;
import com.situ.orderingsystem.utils.Md5Utils;

public class LoginServiceImpl  implements LoginService {
    LoginDAo dao = BeanFactory.getBean(LoginDaoImpl.class);
    @Override
    public User findByUserName(String  username) {
        return dao.findByUsername(username);
    }

    @Override
    public boolean checkLogin(User user, String password) {
        if(user == null){
            return  false;
        }
        String encrypt = Md5Utils.encrypt(password+"{"+user.getUserName()+"}");
        if(user!=null){
            if(encrypt.equals(user.getPassWord())){
                return true;
            }else {
                return  false;
            }

        }
        return  false;

    }

    @Override
    public boolean Update(User user, String username, String password) {
        if(user == null){
            return false;
        }
        String encrypt = Md5Utils.encrypt(password+"{"+user.getUserName()+"}");
         return  dao.update(user,username,encrypt);
    }
}
